<template>
  <div>
    <el-card>
      <h3>商品详情</h3>
      <el-form ref="form" label-width="80px">
        <el-form-item label="商品名称">
          <el-input disabled v-model="product.name"></el-input>
        </el-form-item>
        <el-form-item label="商品描述">
          <el-input disabled v-model="product.subtitle"></el-input>
        </el-form-item>
        <el-form-item label="当前状态">
          <el-input v-if="product.status == '1'" disabled value="在售"></el-input>
          <el-input v-else disabled value="已下架"></el-input>
        </el-form-item>
        <el-form-item label="所属分类">
          <!-- <el-select v-model="value" placeholder="请选择一级品类">
            <el-option
              v-for="item in selectList"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            ></el-option>
          </el-select> -->
          <el-select v-model="selectO" placeholder="请选择一级品类">
            <el-option selected key="555" label="12" value="aa"></el-option>
              <el-option v-for="item in selectOne" :key="item.id" :label="item.name" :value="item.id"></el-option>
          </el-select>
          <el-select v-if="selectO !== ''" v-model="selectT" placeholder="请选择二级品类">
            <el-option v-for="item in selectTwo" :key="item.id" :label="item.name" :value="item.id"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="商品价格">
          <el-input disabled v-model="product.price">
            <template slot="append">元</template>
          </el-input>
        </el-form-item>
        <el-form-item label="商品库存">
          <el-input disabled v-model="product.stock">
            <template slot="append">件</template>
          </el-input>
        </el-form-item>
        <el-form-item label="商品图片">
          <img style="width: 100px; height: 100px" :src="product.imageHost+product.mainImage" alt />
        </el-form-item>
        <el-form-item label="商品详情">
          <p v-html="product.detail"></p>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
import { productInfo } from "../util/http";
import { productType } from "../util/http";
export default {
  // 组件名称
  name: "demo", // 组件参数 接收来自父组件的数据
  props: [],
  components: {},
  data() {
    return {
      product: {},
      selectList: [],
      value: "",
      selectOne: [],
      selectO: '',
      selectTwo: [],
      selectT: "",
    };
  },
  computed: {},
  watch: {},
  methods: {
    async getProduct() {
      const { data: res } = await productInfo(
        `/api/manage/product/detail.do?productId=${this.$store.state.productCheck.id}`
      );
      if (res.status !== 0) return this.$message.error("获取数据失败");
      this.$message.success("获取数据成功");
      this.product = res.data;

      this.selectO=this.product.parentCategoryId
      this.selectT=this.product.categoryId
      const { data: resSelectTwo } = await productType(
        `/api/manage/category/get_category.do?categoryId=${this.product.parentCategoryId}`
      );
      this.selectTwo = resSelectTwo.data;
    },
    async getSelectOne() {
      const { data: res } = await productType(
        `/api/manage/category/get_category.do?categoryId=0`
      );
      if (res.status !== 0) return this.$message.error("获取数据失败");
      this.$message.success("获取数据成功");
      this.selectOne = res.data;
    },
    
  },
  beforeCreate() {},
  created() {
    this.getProduct();
    this.getSelectOne();
  },
  beforeMount() {},
  mounted() {}
};
</script> 
<style scoped>
</style>
